<?php
namespace logic\sys\images;
class Image extends \logic\Base{
    
    // 1平台 2代理商agentid 3主站点msiteid 4会员',
    private $utypeList = [ 'admin'=> 2,'site'=> 3,'member'=> 4];
        
    /**
     * 添加图片
     */
    public function add($param,$picType){        
        $check = [            
            //'albumid'   => '',
            'picurl'    => ['check'=>'must','msg'=>'图片路径不能为空'],
            'picname'   => '',   
            'size'      => '',      
        ];
        $save = pVerify($check,$param);
        
        $userInfo = $this->getUser()->getInfo();
        $role = $this->getUser()->role;
        
        $album = ['tag'=>$picType, 'utype'=> $this->utypeList[$role]];
        if( $role == 'admin' )  $album['uid'] = $userInfo['agentid'];
        if( $role == 'site' )   $album['uid'] = $userInfo['msiteid'];
        if( !$album['uid'] ) logicE('无权限上传图片');
        
        $ImageAlbum = new \logic\sys\images\ImageAlbum($this->CallUser);
        $save['albumid'] = $ImageAlbum->getAlbumId($album);
        
        return D('Image','sysImages')->add($save);
        
    }
    
    /**
     * 读取图片列表
     */
    public function getSelfList($param){
        $userInfo = $this->getUser()->getInfo();
        $role = $this->getUser()->role;  
        
        $param['utype'] = $this->utypeList[$role];
        if( $role == 'admin' )  $param['uid'] = $userInfo['agentid'];
        if( $role == 'site' )   $param['uid'] = $userInfo['msiteid'];
        return D('Image','sysImages')->getlist($param);
    }
    
    /**
     * 读取图片列表
     */
    public function getPublicList($param){
        $param['utype'] = 1;
        $param['tag'] = 'public';
        $param['status'] = 1;
        return D('Image','sysImages')->getlist($param);
    }
    
}